package com.hm.common.plugin.network.netty.su;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.stream.ChunkedWriteHandler;

/**
 * @author shishun.wang
 * @version 1.0
 * @date 2019/4/11 11:32
 * @describe
 */
public class WebSocketChildChannelHandler extends ChannelInitializer<SocketChannel> {
	
	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ch.pipeline().addLast("http-codec", new HttpServerCodec()); // HTTP编码解码器
		
		ch.pipeline().addLast("aggregator", new HttpObjectAggregator(65536)); // 把HTTP头、HTTP体拼成完整的HTTP请求
		ch.pipeline().addLast("http-chunked", new ChunkedWriteHandler()); // 方便大文件传输，不过实质上都是短的文本数据
		ch.pipeline().addLast("http-handler", new HttpRequestHandler());
		ch.pipeline().addLast("websocket-handler",new WebSocketServerHandler());
	}
}
